import HTMLParser
import urllib
import re

urlString = "http://www.tpix.net.tw/member.html"
urlText=[]
check=False
check2=False
td=0
class ParseIXP(HTMLParser.HTMLParser):
    def handle_starttag(self,tag,attrs):
        global check
        global td
        global check2
        if tag=="td":
            td+=1
            if td==2:
                check=True
                check2=True
        if tag=="tr":
            td=0
            check2=False
        if tag=="div" and check2==True:
            check=True
            check2=False
                                    
    def handle_data(self, data):
        global check 
        if data!='\n' and check==True:
            if (re.search("^\d\d*$", data)):
                urlText.append(data)
        check=False
                    
lparser=ParseIXP()
lparser.feed(urllib.urlopen(urlString).read())
filePath="ixp_members.txt"
file=open(filePath, "a")
for item in urlText:
    #print item
    print >> file, "231 %s" % item
file.close()